﻿CREATE VIEW forms.v_GPSAgreement
AS
SELECT     CONVERT(varchar, L_B0.LoanID) AS LoanID, dbo.InitCaps(B0.FirstName + ' ' + B0.LastName + ISNULL(', ' + B1.FirstName + ' ' + B1.LastName, N'')) 
                      AS BuyerName, CASE dbo.clr_VINCheck(CI.VIN) WHEN 1 THEN VIN ELSE '' END AS VIN, CONVERT(varchar, CI.Year) 
                      + ' ' + CI.Make + ' ' + CI.Model AS YearMakeModel, CONVERT(varchar, GETDATE(), 110) AS Date, CONVERT(varchar, DAY(GETDATE())) AS Day, 
                      DATENAME(month, GETDATE()) AS Month, RIGHT(CONVERT(varchar, YEAR(GETDATE())), 2) AS Year, B0.FirstName + ' ' + B0.LastName AS BuyerName0,
                       B1.FirstName + ' ' + B1.LastName AS BuyerName1, CI.Dealer, CI.Make, CI.Model, ISNULL(CI.Series + ' ', '') + ISNULL(CI.Body_Style, '') AS BodyStyle, 
                      A.Street AS BuyerAddress, A.CityName AS BuyerCity, A.Zip AS BuyerZip, A.StateCode AS BuyerState, 'AFC, LLC' AS CompanyName, 
                      'Broward' AS CompanyCounty, 'FL' AS CompanyState
FROM         dbo.t_Borrower AS B0 INNER JOIN
                      dbo.t_Loan_Borrower AS L_B0 ON B0.ID = L_B0.BorrowerID INNER JOIN
                      dbo.v_CarInfo AS CI ON L_B0.LoanID = CI.LoanID INNER JOIN
                      dbo.t_Address AS A ON B0.ID = A.BorrowerID AND A.Pos = 0 LEFT OUTER JOIN
                      dbo.t_Borrower AS B1 INNER JOIN
                      dbo.t_Loan_Borrower AS L_B1 ON B1.ID = L_B1.BorrowerID ON L_B0.LoanID = L_B1.LoanID AND L_B1.Pos = 1
WHERE     (L_B0.Pos = 0)

GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane1', @value = N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[28] 4[33] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "B1"
            Begin Extent = 
               Top = 151
               Left = 734
               Bottom = 341
               Right = 956
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "L_B1"
            Begin Extent = 
               Top = 239
               Left = 526
               Bottom = 347
               Right = 677
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "B0"
            Begin Extent = 
               Top = 61
               Left = 34
               Bottom = 169
               Right = 256
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "L_B0"
            Begin Extent = 
               Top = 160
               Left = 334
               Bottom = 268
               Right = 485
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "CI"
            Begin Extent = 
               Top = 35
               Left = 573
               Bottom = 175
               Right = 776
            End
            DisplayFlags = 280
            TopColumn = 10
         End
         Begin Table = "A"
            Begin Extent = 
               Top = 17
               Left = 335
               Bottom = 125
               Right = 501
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 15
         Width = 284
         Width = 750
         Width = 4275
         Width = 1830', @level0type = N'SCHEMA', @level0name = N'forms', @level1type = N'VIEW', @level1name = N'v_GPSAgreement';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane2', @value = N'Width = 3420
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 6390
         Alias = 1440
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End', @level0type = N'SCHEMA', @level0name = N'forms', @level1type = N'VIEW', @level1name = N'v_GPSAgreement';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPaneCount', @value = 2, @level0type = N'SCHEMA', @level0name = N'forms', @level1type = N'VIEW', @level1name = N'v_GPSAgreement';

